<?php
class EventsController extends AppController{
	var $helpers = array('Html','Form');
	var $name = "Events";
	var $uses = array('Event', 'Visitor','Join');
	function index(){
		
	}
	
	function all(){
		$this->set('events', $this->Event->find('all'));
	}
	
	/* Find available events */
	function available(){
		$this->set('events', $this->Event->find('all',array('conditions' => array('Event.end_date <' => date('Y-m-d'),'Event.end_date !=' => '0000-00-00'))));
	}	
	
	function detail($event_id){
		$this->set('event', $this->Event->find('first', array('conditions' => array('Event.event_id' => $event_id))));
	}
	
	function register(){
		if(!empty($this->data)){
			echo pr($this->data);
			echo pr($this->data['Event']);
			$this->Visitor->save($this->data['Event']);
			
			$join = null;
			$join['join_date'] = date('Y-m-d');
			$join['event_id'] = $this->data['Event']['event_id'];
			$join['user_id'] = $this->Visitor->getLastInsertId();
			$join['ip_reg'] = $_SERVER['REMOTE_ADDR'];
			pr($join);
			$this->Join->save($join);
			
		}
	}
}
?>
